package com.google.shop.product.search.service.impl;

import com.google.shop.product.common.utils.MR;
import com.google.shop.product.search.service.JdService;
import com.google.shop.product.search.vo.AmazonVO;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
/* loaded from: app.jar:BOOT-INF/classes/com/google/shop/product/search/service/impl/JdImpl.class */
public class JdImpl implements JdService {
    private static final Logger log = LoggerFactory.getLogger(JdImpl.class);

    @Override // com.google.shop.product.search.service.JdService
    public MR FindJdPage(String name, Integer pageNum) throws IOException {
        Elements elements = Jsoup.parse(new URL("https://search.jd.com/Search?keyword=" + name.replace(" ", "") + "&page=" + pageNum), 3000).getElementById("J_goodsList").getElementsByTag("li");
        ArrayList<AmazonVO> goodsList = new ArrayList<>();
        Iterator<Element> it = elements.iterator();
        while (it.hasNext()) {
            Element element = it.next();
            String img = element.getElementsByTag("img").eq(0).attr("data-lazy-img");
            System.out.println(img);
            if (!(img == null || img == "")) {
                img = img.substring(2);
            }
            String price = element.getElementsByClass("p-price").eq(0).text();
            String title = element.getElementsByClass("p-name").eq(0).text();
            if (!(title.length() == 0 || img == null)) {
                String httpImg = "http://" + img;
                if (price.split("￥").length > 2) {
                    price = "￥" + price.split("￥")[1];
                }
                goodsList.add(new AmazonVO(title, price, httpImg));
            }
        }
        Iterator<AmazonVO> it2 = goodsList.iterator();
        while (it2.hasNext()) {
            System.out.println(it2.next());
        }
        return MR.ok().put("amazonPage", (Object) goodsList);
    }
}
